package com.huawei.admins.platform.gateway.core.exception;

import org.springframework.http.HttpStatus;

public class GatewayServerException extends RuntimeException {

    private final HttpStatus code;

    public GatewayServerException(HttpStatus code) {
        this.code = code;
    }

    public GatewayServerException(String message, HttpStatus code) {
        super(message);
        this.code = code;
    }

    public GatewayServerException(String message, Throwable cause, HttpStatus code) {
        super(message, cause);
        this.code = code;
    }

    public GatewayServerException(Throwable cause, HttpStatus code) {
        super(cause);
        this.code = code;
    }

    public GatewayServerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, HttpStatus code) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
    }

    public int httpStatus() {
        return this.code != null ? code.value() : HttpStatus.INTERNAL_SERVER_ERROR.value();
    }
}
